package com.bjtech.web.action.management;

import java.util.Date;

import com.bjtech.dao.UserConsultInfoDao;
import com.bjtech.dao.UserConsultReplyDao;
import com.bjtech.domain.UserConsultInfo;
import com.bjtech.domain.UserConsultReply;
import com.bjtech.domain.query.UserConsultReplyQuerySpec;
import com.bjtech.web.action.LyheatBaseAction;

public class UserConsultReplyAction extends LyheatBaseAction {

	private static final long serialVersionUID = 1L;
	private UserConsultReplyDao userConsultReplyDao;
	private UserConsultInfoDao userConsultInfoDao;
	private UserConsultReplyQuerySpec selectBean;
	
	private UserConsultInfo consultInfo;
	private Long infoId;
	
	private String custom;
	
	public void prepare() throws Exception {

	}
	
	public UserConsultReplyAction() throws Exception{
		model = new UserConsultReply();
		selectBean = new UserConsultReplyQuerySpec();
	}
	
	public void setUserConsultReplyDao(UserConsultReplyDao userConsultReplyDao) {
		this.userConsultReplyDao = userConsultReplyDao;
	}

	public String execute(){
		return this.list();
	}
	
	public String list(){
		selectBean.queryParamString();
		list = this.userConsultReplyDao.selectEntityPaginatedList(new UserConsultReply(),selectBean);
		return "list";
	}
	
	public String add(){
		model = this.userConsultReplyDao.selectEntity(new UserConsultReply(),id);
		if(model==null){
			model = new UserConsultReply();
		}
		((UserConsultReply)model).setConsult_id(infoId);
		consultInfo = this.userConsultInfoDao.selectEntity(new UserConsultInfo(), infoId);
		return "edit";
	}
	
	public String save(){
		UserConsultReply entity = (UserConsultReply)model;
		entity.setReply_date(new Date());
		entity.setReply_user_id(this.getUser().getUserId());
		if(entity.getId()==null){
			userConsultReplyDao.insertEntity(entity);
		}else{
			userConsultReplyDao.updateEntity(entity);
		}
//		return "success";
		super.renderJavaScript("window.onload=function(){alert('回复成功！');location.href='UserConsultInfo!reply.action';}");
		return null;
	}
	
	public String edit(){
		model = this.userConsultReplyDao.selectEntity(new UserConsultReply(),id);
		return "edit";
	}

	public String view(){
		model = this.userConsultReplyDao.selectEntity(new UserConsultReply(),id);
		return "view";
	}
	
	public String delete(){
		model = this.userConsultReplyDao.deleteEntity(new UserConsultReply(),id);
		return "success";
	}
	
	public UserConsultReplyQuerySpec getSelectBean() {
		return selectBean;
	}

	public void setSelectBean(UserConsultReplyQuerySpec selectBean) {
		this.selectBean = selectBean;
	}

	public UserConsultInfoDao getUserConsultInfoDao() {
		return userConsultInfoDao;
	}

	public void setUserConsultInfoDao(UserConsultInfoDao userConsultInfoDao) {
		this.userConsultInfoDao = userConsultInfoDao;
	}

	public UserConsultInfo getConsultInfo() {
		return consultInfo;
	}

	public void setConsultInfo(UserConsultInfo consultInfo) {
		this.consultInfo = consultInfo;
	}

	public UserConsultReplyDao getUserConsultReplyDao() {
		return userConsultReplyDao;
	}

	public Long getInfoId() {
		return infoId;
	}

	public void setInfoId(Long infoId) {
		this.infoId = infoId;
	}

	public String getCustom() {
		return custom;
	}

	public void setCustom(String custom) {
		this.custom = custom;
	}
}
